
package grafica.ventanas;

import grafica.controladores.ControladorEmplModFreelance;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;

import logica.datatypes.DataEmpresa;
import logica.datatypes.DataFreelance;

public class empleadoModFreelance {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="178,38"
	private JPanel jContentPane = null;
	private JPanel jPanelCI = null;
	private JLabel jLabelCI = null;
	private JLabel jLabelEmpresa = null;
	private JLabel jLabelNombre = null;
	private JLabel jLabelApellido = null;
	private JLabel jLabelEdad = null;
	private JTextField jTextFieldCI = null;
	private JTextField jTextFieldNombre = null;
	private JTextField jTextFieldApellido = null;
	private JTextField jTextFieldEdad = null;
	private JTextField jTextFieldHoras = null;
	private JButton jButtonCancelar = null;
	private JButton jButtonAceptar = null;
	private JComboBox jComboBox = null;
	private JLabel jLabelMensajes = null;
	private ControladorEmplModFreelance ConEmplFree;
	private DataEmpresa Empresa;
	private DataFreelance dataFreelance;
	private JTextField jTextFieldPrecio = null;
	private JLabel jLabel5 = null;
	private JLabel jLabel6 = null;
	/**
	 * This method initializes jFrame	
	 * 	
	 * @return javax.swing.JFrame	
	 */
	
	public empleadoModFreelance(DataFreelance dataFreelance){
		this.dataFreelance = dataFreelance;
		ConEmplFree = new ControladorEmplModFreelance(this);		
	}
	
	public void setVisible (boolean b){	
		this.getJFrame().setVisible(b);
		cargarDatos();
	}
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setSize(new Dimension(330, 384));
			jFrame.setTitle("MODIFICAR ASALARIADO");
			jFrame.setContentPane(getJContentPane());
			jFrame.setLocationRelativeTo(null);	
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanelCI(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanelCI	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelCI() {
		if (jPanelCI == null) {
			GridBagConstraints gridBagConstraints42 = new GridBagConstraints();
			gridBagConstraints42.gridx = 0;
			gridBagConstraints42.gridy = 7;
			jLabel6 = new JLabel();
			jLabel6.setText("   Recop Hora");
			GridBagConstraints gridBagConstraints33 = new GridBagConstraints();
			gridBagConstraints33.gridx = 0;
			gridBagConstraints33.gridy = 6;
			jLabel5 = new JLabel();
			jLabel5.setText("   Cant. Horas");
			GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
			gridBagConstraints15.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints15.gridy = 7;
			gridBagConstraints15.weightx = 1.0;
			gridBagConstraints15.gridx = 1;
			GridBagConstraints gridBagConstraints32 = new GridBagConstraints();
			gridBagConstraints32.gridx = 1;
			gridBagConstraints32.gridwidth = 2;
			gridBagConstraints32.gridy = 18;
			jLabelMensajes = new JLabel();
			jLabelMensajes.setText("");
			jLabelMensajes.setPreferredSize(new Dimension(200, 26));
			GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
			gridBagConstraints14.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints14.gridy = 2;
			gridBagConstraints14.weightx = 1.0;
			gridBagConstraints14.gridx = 1;
			GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
			gridBagConstraints41.gridx = 0;
			gridBagConstraints41.gridy = 17;
			GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
			gridBagConstraints31.gridx = 1;
			gridBagConstraints31.gridy = 17;
			GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
			gridBagConstraints13.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints13.gridy = 6;
			gridBagConstraints13.weightx = 1.0;
			gridBagConstraints13.gridx = 1;
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints12.gridy = 5;
			gridBagConstraints12.weightx = 1.0;
			gridBagConstraints12.gridx = 1;
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints11.gridy = 4;
			gridBagConstraints11.weightx = 1.0;
			gridBagConstraints11.gridx = 1;
			GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
			gridBagConstraints10.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints10.gridy = 3;
			gridBagConstraints10.weightx = 1.0;
			gridBagConstraints10.gridx = 1;
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints8.gridy = 0;
			gridBagConstraints8.weightx = 1.0;
			gridBagConstraints8.gridx = 1;
			gridBagConstraints10.insets = new Insets(10,10,10,10);
			gridBagConstraints8.insets = new Insets(10,10,10,10);
			gridBagConstraints12.insets = new Insets(10,10,0,10);
			gridBagConstraints13.insets = new Insets(10,10,10,10);
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.gridx = 0;
			gridBagConstraints4.gridy = 5;
			jLabelEdad = new JLabel();
			jLabelEdad.setText("   Edad");
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.gridx = 0;
			gridBagConstraints3.gridy = 4;
			jLabelApellido = new JLabel();
			jLabelApellido.setText("   Apellido");
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 0;
			gridBagConstraints2.gridy = 3;
			jLabelNombre = new JLabel();
			jLabelNombre.setText("   Nombre");
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 0;
			gridBagConstraints1.gridy = 2;
			jLabelEmpresa = new JLabel();
			jLabelEmpresa.setText("   Empresa");
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			jLabelCI = new JLabel();
			jLabelCI.setText("   CI");
			jPanelCI = new JPanel();
			jPanelCI.setLayout(new GridBagLayout());
			jPanelCI.add(jLabelCI, gridBagConstraints);
			jPanelCI.add(jLabelEmpresa, gridBagConstraints1);
			jPanelCI.add(jLabelNombre, gridBagConstraints2);
			jPanelCI.add(jLabelApellido, gridBagConstraints3);
			jPanelCI.add(jLabelEdad, gridBagConstraints4);
			jPanelCI.add(getJTextFieldCI(), gridBagConstraints8);
			jPanelCI.add(getJTextFieldNombre(), gridBagConstraints10);
			jPanelCI.add(getJTextFieldApellido(), gridBagConstraints11);
			jPanelCI.add(getJTextFieldEdad(), gridBagConstraints12);
			jPanelCI.add(getJTextFieldHoras(), gridBagConstraints13);
			jPanelCI.add(getJButtonCancelar(), gridBagConstraints31);
			jPanelCI.add(getJButtonAceptar(), gridBagConstraints41);
			jPanelCI.add(getJComboBox(), gridBagConstraints14);
			jPanelCI.add(jLabelMensajes, gridBagConstraints32);
			jPanelCI.add(getJTextFieldPrecio(), gridBagConstraints15);
			jPanelCI.add(jLabel5, gridBagConstraints33);
			jPanelCI.add(jLabel6, gridBagConstraints42);
		}
		return jPanelCI;
	}

	/**
	 * This method initializes jTextFieldCI	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldCI() {
		if (jTextFieldCI == null) {
			jTextFieldCI = new JTextField();
			jTextFieldCI.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldCI;
	}

	/**
	 * This method initializes jTextFieldNombre	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldNombre() {
		if (jTextFieldNombre == null) {
			jTextFieldNombre = new JTextField();
			jTextFieldNombre.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldNombre;
	}

	/**
	 * This method initializes jTextFieldApellido	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldApellido() {
		if (jTextFieldApellido == null) {
			jTextFieldApellido = new JTextField();
			jTextFieldApellido.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldApellido;
	}

	/**
	 * This method initializes jTextFieldEdad	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldEdad() {
		if (jTextFieldEdad == null) {
			jTextFieldEdad = new JTextField();
			jTextFieldEdad.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldEdad;
	}

	/**
	 * This method initializes jTextFieldHoras	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldHoras() {
		if (jTextFieldHoras == null) {
			jTextFieldHoras = new JTextField();
			jTextFieldHoras.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldHoras;
	}
	/**
	 * This method initializes jButtonCancelar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancelar() {
		if (jButtonCancelar == null) {
			jButtonCancelar = new JButton();
			jButtonCancelar.setText("Cancelar");
			ActionListener BotonCancelar = new ActionListener(){
				public void actionPerformed (ActionEvent e){ 				
					jFrame.dispose();				
				}
			};
			jButtonCancelar.addActionListener(BotonCancelar );
		}
		return jButtonCancelar;
	}
	/**
	 * This method initializes jButtonAceptar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAceptar() {
		if (jButtonAceptar == null) {
			jButtonAceptar = new JButton();
			jButtonAceptar.setText("Aceptar");
			ActionListener ButtonAceptar = new ActionListener(){
				public void actionPerformed (ActionEvent e){						
					ConEmplFree.ModEmplFreelance(Integer.parseInt(getJTextFieldCI().getText()), getJTextFieldNombre().getText().toString(), getJTextFieldApellido().getText().toString(), Integer.parseInt(getJTextFieldEdad().getText()), Empresa.getRut(), Integer.parseInt(getJTextFieldHoras().getText()), Float.parseFloat(getJTextFieldPrecio().getText()));
					System.out.println("Fin valor");
				}
			};
			jButtonAceptar.addActionListener(ButtonAceptar);
		}
		return jButtonAceptar;
	}
	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();	
			jComboBox.setPreferredSize(new Dimension(180, 25));
			////Completra, Cargar empresas existentes en base
			Empresa = ConEmplFree.getEmprea(dataFreelance.getRutEmpresa());
			jComboBox.addItem(Empresa.getRazon_Social());		
		
		}
		return jComboBox;
	}
	
	public void setJTextAreaMensajes(String info){
		this.jLabelMensajes.setText(info);
	}
	
	public void limpiarData(){
		this.jTextFieldNombre.setEditable(false);
		this.jTextFieldApellido.setEditable(false);
		this.jTextFieldEdad.setEditable(false);
		this.jTextFieldHoras.setEditable(false);
		this.jButtonAceptar.setVisible(false);
		this.jButtonCancelar.setText("Aceptar");
		this.jTextFieldPrecio.setEditable(false);
	}
	
	private void cargarDatos(){
		this.jTextFieldCI.setEnabled(false);
		this.jComboBox.setEnabled(false);
		this.jTextFieldCI.setText(String.valueOf(dataFreelance.getCi()));
		this.jTextFieldNombre.setText(dataFreelance.getNombre());
		this.jTextFieldApellido.setText(dataFreelance.getApellido());
		this.jTextFieldEdad.setText(String.valueOf(dataFreelance.getEdad()));
		this.jTextFieldHoras.setText(String.valueOf(dataFreelance.getCantidad_horas()));
		this.jTextFieldPrecio.setText(Float.toString(dataFreelance.getPrecio()));
	}

	/**
	 * This method initializes jTextFieldPrecio	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldPrecio() {
		if (jTextFieldPrecio == null) {
			jTextFieldPrecio = new JTextField();
			jTextFieldPrecio.setPreferredSize(new Dimension(180, 25));
		}
		return jTextFieldPrecio;
	}
}
